package com.tarena.test.luban.demo.order.dubbo.test;

import com.tarena.luban.demo.stock.api.DubboTestApi;
import org.apache.dubbo.config.ReferenceConfig;
import org.apache.dubbo.config.RegistryConfig;
import org.apache.dubbo.config.bootstrap.DubboBootstrap;

public class DubboConsumer {
    public static void main(String[] args) {
        DubboTestApi proxy = getProxy();
        String result = proxy.sayHi("李富贵");
        System.out.println(result);
    }
    public static DubboTestApi getProxy(){
        // 到注册中心获取信息,建立连接,调用目标借口方法
        ReferenceConfig<DubboTestApi> consumerConfig= new ReferenceConfig<>();
        consumerConfig.setInterface(DubboTestApi.class);
        DubboBootstrap boot = DubboBootstrap.getInstance();
        boot.application("order-consumer");
        boot.registry(new RegistryConfig("nacos://localhost:8848"));
        boot.reference(consumerConfig);
        DubboTestApi dubboTestApi = consumerConfig.get();
        System.out.println("consumer 获取的对象实际类型:"+dubboTestApi.getClass().getName());
        return dubboTestApi ;
    }
}
